package at.ac.uniklu.rallyemaster.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import at.ac.uniklu.rallyemaster.R;
import at.ac.uniklu.rallyemaster.RallyeMaster;
import at.ac.uniklu.rallyemaster.adapters.DBTrack;
import at.ac.uniklu.rallyemaster.domain.Track;


public class StoreTrackActivity extends Activity{

	private EditText name;
	private EditText notes; 
	private Button save; 
	
	private DBTrack dbTrack;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		dbTrack = new DBTrack();
		setContentView(R.layout.storetrack_layout);
		
		name = (EditText) findViewById(R.id.editName); 
		notes = (EditText) findViewById(R.id.editNotes);
		
		save = (Button) findViewById(R.id.buttonStart);
		save.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
							
				String _name = name.getText().toString();
				String _notes = notes.getText().toString();
	
				Track _track = new Track();
				_track.setName(_name);
				_track.setNotes(_notes);
				
				dbTrack.insertTrack(_track);
				int lastInsertedID = dbTrack.getLastInsertedTrackID();
				RallyeMaster.logDebug("Last inserted ID :" + lastInsertedID);
				
				Intent intent = new Intent(StoreTrackActivity.this, TrackingActivity.class);
				intent.putExtra("LastInsertID", lastInsertedID);
				startActivity(intent);
				 
				}

		});

	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

}
